package cn.kaguyaever.utils;

import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.Date;

public class MailUtil {
    //邮箱参数
    public static String emailAccount = ;
    public static String emailPassword = ;
    public static String emailSMTPHost = ;
    public static String receiveMailAccount = "";

    public static MimeMessage creatMimeMessage(Session session, String sendMail, String receiveMail, String html, String username) throws MessagingException, IOException {
        //创建邮件对象
        MimeMessage message = new MimeMessage(session);
        //发件人
        message.setFrom(new InternetAddress(sendMail, "BlickWinkel", "UTF-8"));
        //收件人
        message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, username, "UTF-8"));
        //邮件主题
        message.setSubject("邮箱验证", "UTF-8");
        //邮件正文
        message.setContent(html, "text/html;charset=UTF-8");
        //设置发送时间
        message.setSentDate(new Date());
        //保存设置
        message.saveChanges();

        return message;
    }
}
